package com.jy.adscm.operation.base.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.annotation.AdscmLogger;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.base.bean.TaskWorkPlanDetail;
import com.jy.adscm.operation.base.service.TaskWorkPlanDetailService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 个人工作计划详情 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2020-05-26
 */
@RestController
@RequestMapping("/adscm/operation/taskWorkPlanDetailDetail")
public class TaskWorkPlanDetailController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    TaskWorkPlanDetailService taskWorkPlanDetailService;
    @AdscmLogger("新增个人计划")
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody TaskWorkPlanDetail taskWorkPlanDetail, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = taskWorkPlanDetailService.insertTaskWorkPlanDetail(taskWorkPlanDetail,token);
        return new SimpleCoreResponse("200","新增成功",insert);
    }
    @AdscmLogger("修改个人计划")
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody TaskWorkPlanDetail taskWorkPlanDetail, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = taskWorkPlanDetailService.updateTaskWorkPlanDetail(taskWorkPlanDetail,token);
        return new SimpleCoreResponse("200","修改成功",insert);
    }
    @AdscmLogger("删除个人计划")
    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Long id, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = taskWorkPlanDetailService.deleteTaskWorkPlanDetail(id,token);
        return new SimpleCoreResponse("200","删除成功",insert);
    }
    @RequestMapping("selectByPid/{id}")
    public SimpleCoreResponse select(@PathVariable Long id, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<TaskWorkPlanDetail> taskWorkPlanDetails= taskWorkPlanDetailService.selectByPid(id);
        return new SimpleCoreResponse("200","查询成功",taskWorkPlanDetails);
    }
}

